package com.mb.app.appused.views;

import android.content.Context;
import android.graphics.drawable.StateListDrawable;
import android.view.View;

public class CustomSelector {
	public int nomal;
	public int focuse;
	Context context;

	public CustomSelector(Context context, int nomal, int focuse) {
		this.nomal = nomal;
		this.focuse = focuse;
		this.context = context;
	}

	@SuppressWarnings("deprecation")
	public void setState(View view) {
		StateListDrawable drawable = new StateListDrawable();
		// Non focused states
		drawable.addState(new int[] { -android.R.attr.state_focused, -android.R.attr.state_selected,
				-android.R.attr.state_pressed }, context.getResources().getDrawable(nomal));
		drawable.addState(new int[] { -android.R.attr.state_focused, android.R.attr.state_selected,
				-android.R.attr.state_pressed }, context.getResources().getDrawable(nomal));

		// Focused states
		drawable.addState(new int[] { android.R.attr.state_focused, -android.R.attr.state_selected,
				-android.R.attr.state_pressed }, context.getResources().getDrawable(focuse));
		drawable.addState(new int[] { android.R.attr.state_focused, android.R.attr.state_selected,
				-android.R.attr.state_pressed }, context.getResources().getDrawable(focuse));
		// Pressed
		drawable.addState(new int[] { android.R.attr.state_selected, android.R.attr.state_pressed },
				context.getResources().getDrawable(focuse));
		drawable.addState(new int[] { android.R.attr.state_pressed }, context.getResources().getDrawable(focuse));
		view.setBackgroundDrawable(drawable);
	}

	@SuppressWarnings("deprecation")
	public static void setState(Context context, View view, int nomal, int focuse) {
		StateListDrawable drawable = new StateListDrawable();
		// Non focused states
		drawable.addState(new int[] { -android.R.attr.state_focused, -android.R.attr.state_selected,
				-android.R.attr.state_pressed }, context.getResources().getDrawable(nomal));
		drawable.addState(new int[] { -android.R.attr.state_focused, android.R.attr.state_selected,
				-android.R.attr.state_pressed }, context.getResources().getDrawable(nomal));

		// Focused states
		drawable.addState(new int[] { android.R.attr.state_focused, -android.R.attr.state_selected,
				-android.R.attr.state_pressed }, context.getResources().getDrawable(focuse));
		drawable.addState(new int[] { android.R.attr.state_focused, android.R.attr.state_selected,
				-android.R.attr.state_pressed }, context.getResources().getDrawable(focuse));
		// Pressed
		drawable.addState(new int[] { android.R.attr.state_selected, android.R.attr.state_pressed },
				context.getResources().getDrawable(focuse));
		drawable.addState(new int[] { android.R.attr.state_pressed }, context.getResources().getDrawable(focuse));
		view.setBackgroundDrawable(drawable);
	}
}
